package com.example.news0515.util;

import org.json.JSONException;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class HttpUtil {
    public String connectServer(String type) throws IOException, JSONException {
        String url = "http://v.juhe.cn/toutiao/index?type=" + type + "&key=6e56619b24953aa32af1f9647737a30d";
        OkHttpClient client = new OkHttpClient();
        RequestBody body = new FormBody.Builder().add("", "").build();
        Request request = new Request.Builder().post(body).url(url).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful()){
            String data=response.body().string();
            return data;
        }else {
            return "网络连接失败，请重新配置您的网络";
        }
    }
}
